package cn.sdormitory.controller.canteen;

import cn.sdormitory.canteen.service.FoodHealthCartService;
import cn.sdormitory.canteen.service.FoodOrderService;
import cn.sdormitory.canteen.vo.FoodHealthCartVO;
import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.utils.ImageToTextAIUtils;
import cn.sdormitory.common.utils.RedisUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@Api(tags = "food-Health-Cart=> 健康证")
@RequestMapping("/food/healthCart")
public class FoodHealthCartController {

    @Autowired
    private FoodHealthCartService foodHealthCartService;


    @ApiOperation("getHealthCartPageList => 分页查询健康证")
    @PostMapping(value = "/getHealthCartPageList")
    public CommonResult<IPage<FoodHealthCartVO>> getHealthCartPageList(@RequestBody Map<String,Object> map){
        IPage<FoodHealthCartVO> pageList =  foodHealthCartService.getPage(map);
        return CommonResult.success(pageList);
    }

    @ApiOperation("addOrUpdateHealthCartInfo => 新增or修改健康证信息")
    @PostMapping(value = "/addOrUpdateHealthCartInfo")
    public CommonResult<Integer> addOrUpdateHealthCartInfo(@RequestBody FoodHealthCartVO vo){
        int num =  foodHealthCartService.saveOrUpdateFoodHealthCart(vo);
        if(num==0){
            CommonResult.failed();
        }
        return CommonResult.success();
    }

    @ApiOperation("deleteHealthCartById => 根据ID删除健康证")
    @PostMapping(value = "/deleteHealthCartById")
    public CommonResult<Integer> deleteHealthCartById(@RequestBody FoodHealthCartVO vo){
        int num =  foodHealthCartService.deleteHealthCartById(vo.getId());
        if(num==0){
            CommonResult.failed();
        }
        return CommonResult.success();
    }

    @ApiOperation("autoRecognitionPhoto => 自动识别出照片信息")
    @GetMapping(value = "/autoRecognitionPhoto")
    public CommonResult<Map<String,String>> autoRecognitionHealthCartPhoto(@RequestParam("fileName")String fileName){
        Map<String,String> map = foodHealthCartService.autoRecognitionHealthCartPhoto(fileName);
        return CommonResult.success(map);
    }




}
